<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //   function CreateObj(name) {
      //     this.name = name;
      //   }

      // 函数原型
      //   CreateObj.prototype.say = function () {
      //     console.log(this.name, "hello");
      //   };
      class CreateObj {
        // 构造器函数
        constructor(name) {
          this.name = name;
        }

        say() {
          console.log(this.name, "hello"); // cxm hello
        }
      }

      var obj = new CreateObj("cxm");
      console.log(obj); //CreateObj {name: 'cxm'}

      obj.say();
    </script>
  </body>
</html>
